<?php 

require_once("../Watajax.class.php");

mysql_connect('localhost','watajax','watajax');
mysql_select_db('watajax');



if ($_GET["from_array"] != "") {
	$w = new WatajaxArray();
	$w->columns = array(
		"id" => array("name" => "#", "sort_type" => "numeric", "hide" => true),
		"firstname" => array("name" => "First name"),
		"lastname" => array("name" => "Last name"),
		"email" => array("name" => "E-mail adress", "transform" => "<a href=\"mailto:!email\">!email</a>"),
		"group" => array("name" => "Grupp", "filter" => "select"),
		"gender" => array("name" => "K&ouml;n", "filter" => "select"),
		"tools" => array("name" => "#", "virtual" => true, "transform" => "<a href=\"?edit=!id\">edit</a>")	
	);
	
	$w->data = array(
		array("ID" => 1, "firstname" => "Christoffer", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 2, "firstname" => "Stefan", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 3, "firstname" => "Jens", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "mix"),
		array("ID" => 4, "firstname" => "Henrik", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 5, "firstname" => "Klas", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "sales", "gender" => "man"),
		array("ID" => 6, "firstname" => "Mossan", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 7, "firstname" => "Erik", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 8, "firstname" => "Christoffer", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 9, "firstname" => "Stefan", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 10, "firstname" => "Jens", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "mix"),
		array("ID" => 10, "firstname" => "Tomas", "lastname" => "Lindahl", "email" => "tomas@westart.se", "group" => "development", "gender" => "mix"),
		array("ID" => 11, "firstname" => "Henrik", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man"),
		array("ID" => 12, "firstname" => "Klas", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "sales", "gender" => "man"),
		array("ID" => 13, "firstname" => "Mossan", "lastname" => "Sandberg", "email" => "christoffer@westart.se", "group" => "development", "gender" => "man")
	);

} else {
	$w = new WatajaxSql();
	$w->columns = array(
		"id" => array("name" => "#", "sort_type" => "numeric"),
		"brand" => array("name" => "M&auml;rke", "filter" => "select"),
		"model" => array("name" => "Model"),
		"modeldescription" => array("name" => "Beskrivning"),
		"yearmodel" => array("name" => "&Aring;rsmodell", "sort_type" => "numeric"),	
		"miles" => array("name" => "Mil", "sort_type" => "numeric"),
		"price-sek" => array("name" => "Pris", "sort_type" => "numeric"),	
		"gearboxtype" => array("name" => "V&auml;xell&aring;da", "filter" => "select"),	
		"fueltype" => array("name" => "Br&auml;nsle", "filter" => "select"),
                "environment" => array("name" => "Milj&ouml;", "filter" => "select", "transform" => "return convertEnv(!environment);", "eval_transform" => true, "select_filter_values" => array(1 => "Miljbil", 0 => "Miljbov"))
	);

}
	
$w->run();

function convertEnv($id) {
    if ($id == 1) {
        return "Milj&ouml;bil";
    } else {
        return "Milj&ouml;bov";
    }
}

?>